﻿using System;
using System.Collections;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Protocolo;

public partial class asistencias : Page
{
    private static HtmlTable _Guias;

    private static IList _reg;

    public IList reg
    {
        get { return _reg; }
        set { _reg = value; }
    }

    public static HtmlTable Guias
    {
        get { return _Guias; }
        set { _Guias = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            IList evens = Control_calendario.evento_asistencia();
            if (evens.Count > 0)
            {
                Evento even;
                ListItem temp;
                PanelEventos.Visible = true;
                temp = new ListItem("-- Seleccione un evento --", "0");
                ListEventos.Items.Add(temp);
                for (int i = 0; i < evens.Count; i++)
                {
                    even = (Evento) evens[i];
                    temp = new ListItem(even.Nombre + ", " + even.Hora_ini, even.id_evento + "");
                    ListEventos.Items.Add(temp);
                }
            }
            else
            {
                Mensaje.Visible = true;
                Menssage.Text = "Actualmente no hay eventos al que pueda confirmar asistencia de los guias";
                Menssage.ForeColor = Color.Green;
            }
        }
    }
    protected void ListEventos_SelectedIndexChanged(object sender, EventArgs e)
    {
        string id = ListEventos.SelectedValue;
        Persona person;
        reg = Control_calendario.Guias_Registro(id);
        if (reg.Count > 0)
        {
            Guias = new HtmlTable();
            Guias.Width = "506px";
            ListGuias.Controls.Add(Guias);
            ListGuias.Visible = true;
            HtmlTableRow r = new HtmlTableRow();
            HtmlTableCell a = new HtmlTableCell();
            HtmlTableCell b = new HtmlTableCell();
            HtmlTableCell c = new HtmlTableCell();
            a.BorderColor = b.BorderColor = c.BorderColor = "#FFFFFF";
            a.BgColor = b.BgColor = c.BgColor = "#a9a9a9";
            a.Controls.Add(new LiteralControl("<b>#</b>"));
            b.Controls.Add(new LiteralControl("<b>Nombre y Apellido</b>"));
            c.Controls.Add(new LiteralControl("<b>Asistencia</b>"));
            r.Cells.Add(a);
            r.Cells.Add(b);
            r.Cells.Add(c);
            Guias.Rows.Add(r);
            for (int i = 0; i < reg.Count; i++)
            {
                person = (Persona) reg[i];
                r = new HtmlTableRow();
                a = new HtmlTableCell();
                b = new HtmlTableCell();
                c = new HtmlTableCell();
                a.BorderColor = b.BorderColor = c.BorderColor = "#FFFFFF";
                if (i%2 == 0)
                {
                    a.BgColor = b.BgColor = c.BgColor = "#E0E9F5";
                }
                else
                {
                    a.BgColor = b.BgColor = c.BgColor = "#D3D3D3";
                }
                a.Controls.Add(new LiteralControl(i + 1 + ""));
                b.Controls.Add(new LiteralControl(person.Apellido + " " + person.Apellido2 + ", " + person.Nombre));
                c.Controls.Add(new LiteralControl("<input type='checkbox' value='1' id='asistencia" + i + 1 + "'/>"));
                r.Cells.Add(a);
                r.Cells.Add(b);
                r.Cells.Add(c);
                Guias.Rows.Add(r);
            }
        }
    }
    protected void Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
    protected void Accept_Click(object sender, EventArgs e)
    {
        for (int i=1;i<=reg.Count; i++)
        {
            CheckBox check = (CheckBox)Guias.FindControl("asistencia" + i);
        }
    }
}
